import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class HomeItemPage1 extends StatefulWidget {
  final num pageIndex;
  final String pageTitle;
  HomeItemPage1(this.pageIndex, this.pageTitle);
  @override
  _HomeItemPage1State createState() => _HomeItemPage1State();
}

class _HomeItemPage1State extends State<HomeItemPage1> {
  RefreshController refreshController = new RefreshController();
  // 下拉刷新 水滴效果
  Widget refreshWaterDropHeader = WaterDropHeader(waterDropColor: Colors.blue);
  // 这个自定义下拉条 只显示小圈圈
  Widget refreshMaterialClassicHeader =
      MaterialClassicHeader(color: Colors.blue, backgroundColor: Colors.white);
  // 下拉 划出效果
  Widget refreshClassicHeader = ClassicHeader();

  // MaterialClassicHeader(color:Colors.blue,backgroundColor:Colors.white); 这个自定义下拉条 只显示小圈圈
  //  这个headre 有一个出来部分的效果
  // ClassicHeader(
  //     idleText: "下拉刷新",
  //     releaseText: "释放刷新",
  //     refreshingText: "刷新中",
  //     failedText: "刷新失败",
  //     completeText: "刷新成功");

  //  defaultTargetPlatform == TargetPlatform.iOS
  //     ? ClassicHeader(
  //         idleText: "下拉刷新",
  //         releaseText: "释放刷新",
  //         refreshingText: "刷新中",
  //         failedText: "刷新失败",
  //         completeText: "刷新成功")
  //     : WaterDropHeader(
  //         refresh: Text("加载中..."),
  //         complete: Text("刷新成功"),
  //         failed: Text("刷新失败"),
  //       );

  final LoadIndicator defaultFooter = ClassicFooter();

  // 在配置了本地的语言支持的时候，就会根据本地的预览才展示默认英文
  // ClassicFooter(
  //     idleText: "上拉加载",
  //     failedText: "加载失败",
  //     loadingText: "加载中...",
  //     noDataText: "没有更多啦",
  //     canLoadingText: "松开加载");

  // CustomFooter(
  //   builder: (BuildContext context, LoadStatus mode) {
  //     Widget body;
  //     if (mode == LoadStatus.idle) {
  //       body = Text("上拉加载");
  //     } else if (mode == LoadStatus.loading) {
  //       body = CupertinoActivityIndicator();
  //     } else if (mode == LoadStatus.failed) {
  //       body = Text("加载失败！点击重试！");
  //     } else if (mode == LoadStatus.canLoading) {
  //       body = Text("松手,加载更多!");
  //     } else {
  //       body = Text("没有更多数据了!");
  //     }
  //     return Container(
  //       height: 55.0,
  //       child: Center(child: body),
  //     );
  //   },
  // );

  @override
  Widget build(BuildContext context) {
    // return Container(
    //   color: Colors.grey[300],
    //   child: SmartRefresher(
    //     enablePullDown: true,
    //     enablePullUp: true,
    //     header: refreshWaterDropHeader,
    //     footer: defaultFooter,
    //     controller: refreshController,
    //     onRefresh: onRefresh,
    //     onLoading: onLoading,
    //     physics: BouncingScrollPhysics(),
    //     child: buildListView(),
    //   ),
    // );
    return Container(
      color: Colors.grey[300],
      child: buildListView(),
    );
  }

  onRefresh() async {
    print("下拉刷新回调");
    Future.delayed(new Duration(milliseconds: 3000), () {
      refreshController.refreshCompleted();
    });
  }

  onLoading() async {
    print("上拉加载回调");
    Future.delayed(new Duration(milliseconds: 3000), () {
      // refreshController.loadComplete();
      refreshController.loadNoData();
    });
  }

  buildListView() {
    return ListView.builder(
        padding: EdgeInsets.only(top: 0),
        itemCount: 10,
        // physics: BouncingScrollPhysics(),
        itemBuilder: (BuildContext context, int index) {
          // if (index == 0 && widget.pageIndex == 0) {
          //   return buildBannerWidget();
          // }
          return Container(
            height: 130,
            margin: EdgeInsets.only(top: 5),
            padding: EdgeInsets.all(10),
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("GGB flutter奇遇记",
                    style:
                        TextStyle(fontSize: 17, fontWeight: FontWeight.bold)),
                SizedBox(height: 10),
                Text(
                  "我喜欢并习惯了对变化的东西保持着距离，这样才会知道什么是最不会被时间抛弃的。比如爱一个人，充满了变数，我于是后退一步，精进的看着，知道看到真诚的感情。",
                  overflow: TextOverflow.ellipsis,
                  maxLines: 2,
                  style: TextStyle(color: Colors.grey, fontSize: 14),
                ),
                SizedBox(height: 10),
                Row(
                  children: [
                    Text("GGB-Hacker",
                        style:
                            TextStyle(fontSize: 12, color: Colors.grey[500])),
                    SizedBox(width: 16),
                    Icon(
                      Icons.thumb_up,
                      size: 16,
                      color: Colors.grey[500],
                    ),
                    SizedBox(width: 6),
                    Text("20",
                        style:
                            TextStyle(fontSize: 12, color: Colors.grey[500])),
                    SizedBox(width: 16),
                    Icon(
                      Icons.share,
                      size: 16,
                      color: Colors.grey[500],
                    ),
                    SizedBox(width: 6),
                    Text("200",
                        style:
                            TextStyle(fontSize: 12, color: Colors.grey[500])),
                  ],
                ),
              ],
            ),
          );
        });
  }
}
